package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao extends BaseStudentDao {
    private static Student[] stuArr = new Student[5];

    public boolean addStudent(Student stu) {
        boolean result = false;
        for (int i = 0; i < stuArr.length; i++) {
            if (stuArr[i] == null) {
                stuArr[i] = stu;
                result = true;
                break;
            }
        }
        return result;
    }

    public Student[] getStuArr() {
        return stuArr;
    }

    public void deleteStudentById(String id) {
        for (int i = 0; i < stuArr.length; i++) {
            Student stu = stuArr[i];
            if(id.equals(stu.getId())){
                stuArr[i] = null;
            }
        }
    }

    public void updateStudent(String id, Student stu) {
        for (int i = 0; i < stuArr.length; i++) {
            Student newStu = stuArr[i];
            if(id.equals(newStu.getId())){
                stuArr[i] = stu;
            }
        }
    }
}
